unit reload_thumbnails_thread;

interface

uses
  Classes;

type
  TReloadThumbnails = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
  end;

implementation

{ Important: Methods and properties of objects in visual components can only be
  used in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure TReloadThumbnails.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

uses image_hiewer_unit, GDIPOBJ, GDIPUTIL, ComCtrls, Graphics;

{ TReloadThumbnails }

procedure TReloadThumbnails.Execute;
var i: integer;
    thumb_image1: TGPImage;
    encoderClsid: TGUID;
    tmp_bmp: TBitmap;
    cur_image: TImageInfo;
begin
  for i := 0 to FormMain.ListView1.Items.Count - 1 do
    begin
      cur_image := TImageInfo(TTreeNode(FormMain.ListView1.Items[i].Data).Data);

      thumb_image1 := TGPImage.Create(FormMain.root_folder + '\' + cur_image.GetRealFilename);
      GetEncoderClsid('image/bmp', encoderClsid);
      thumb_image1.GetThumbnailImage(120, 90).Save(GetFileNameTmpThumbnail(FormMain.temp_folder_path, cur_image.file_name) + '.bmp', encoderClsid);
      thumb_image1.Free;

      tmp_bmp := TBitmap.Create;
      tmp_bmp.LoadFromFile(GetFileNameTmpThumbnail(FormMain.temp_folder_path, cur_image.file_name) + '.bmp');
      FormMain.ThumbsImageList.Replace(FormMain.ListView1.Items[i].ImageIndex, tmp_bmp, nil);
    end;
end;

end.
